package com.medicine.hbp.base;

import org.kymjs.kjframe.ui.BindView;

import com.medicine.hbp.ui.TopView;
import com.medicine.hbp.R;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * 首页活动
 * 
 * @author wanghua
 *
 */
public class WebActivity extends BaseActivity {

	private String url = "";
	private String name = "";

	@Override
	protected void onCreate(Bundle savedactivityState) {
		super.onCreate(savedactivityState);
		setContentView(R.layout.home_act);
		initTop();
		WebView webView = (WebView) findViewById(R.id.webView_act);
		webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
		webView.setDownloadListener(new DownloadListener() {
			@Override
			public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
					long contentLength) {
				// TODO Auto-generated method stub
				Uri uri = Uri.parse(url);
				Intent intent = new Intent(Intent.ACTION_VIEW, uri);
				startActivity(intent);
			}
		});

		/*
		 * webView.setWebChromeClient(new WebChromeClient(){
		 * 
		 * @Override public boolean onJsAlert(WebView view, String url, String
		 * message, JsResult result) { return super.onJsAlert(view, url,
		 * message, result); }
		 * 
		 * });
		 */
		webView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
		});
		url = getIntent().getStringExtra("URL");
		webView.loadUrl(url);
	}

	private void initTop() {
		name = getIntent().getStringExtra("NAME");
		TopView topview = (TopView) findViewById(R.id.topview);
		topview.setTitle(name);
		topview.setLeftVisibility(View.GONE);
		topview.setLeftVisibilityExit(View.VISIBLE);
		topview.setRightVisibility(View.INVISIBLE);
		topview.setLeftOnClickExit(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
	}
}
